package cn.gztang.service.impl;

import cn.gztang.entity.po.UserInfo;
import cn.gztang.entity.vo.UserInfoVO;
import cn.gztang.mapper.UserInfoMapper;
import cn.gztang.util.DozerUtil;
import cn.gztang.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author GaoFeng2017
 * @date 2018/9/9 17:25
 */
@Service
public class UserServiceImpl implements cn.gztang.service.UserService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private DozerUtil dozerUtil;

    @Override
    public UserInfo findByPassword(String account, String password) {
        return userInfoMapper.selectByPassword(account, StringUtil.getMD5(password));
    }

    @Override
    public Integer updateUserInfo(UserInfo userInfo) {
        return userInfoMapper.updateByPrimaryKeySelective(userInfo);
    }

    @Override
    public Integer addUserInfo(UserInfo userInfo) {
        return userInfoMapper.insertSelective(userInfo);
    }

    @Override
    public UserInfo findByAccount(String account) {
        return userInfoMapper.selectByAccount(account);
    }

    @Override
    public List<UserInfoVO> findAllUser() {
       return dozerUtil.mapList(userInfoMapper.selectAll(),UserInfoVO.class);
    }
}
